package com.five.welcome.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.five.welcome.entity.WelcomeProgress;
import com.five.welcome.dao.WelcomeProgressMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.five.welcome.service.WelcomeProgressService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ywt
 * @since 2024-07-24
 */
@Service
public class WelcomeProgressServiceImpl extends ServiceImpl<WelcomeProgressMapper, WelcomeProgress>
        implements WelcomeProgressService {
    @Autowired
    private WelcomeProgressMapper welcomeProgressMapper;


    @Override
    public void addProgress(String sNumber) {
        welcomeProgressMapper.addProgress(sNumber);
    }

    public void updateValue(String option, String sNumber) {
        UpdateWrapper<WelcomeProgress> wrapper = new UpdateWrapper<>();
        wrapper.set(option, 1)
                .eq("s_number", sNumber);
        int update = welcomeProgressMapper.update(wrapper);
        if (update > 0) {
            wrapper.clear();
        }
    }

    @Override
    public WelcomeProgress getProgressBySNumber(String sNumber) {
        return welcomeProgressMapper.getProgressBySNumber(sNumber);
    }

    @Override
    public List<WelcomeProgress> getAllProgress() {
        return welcomeProgressMapper.getAllProgress();
    }

    @Override
    public Page<WelcomeProgress> getAllProgressOfPage(Integer pageNumber, Integer pageSize,
                                                      Integer registered, Integer roomed,
                                                      Integer geted, Integer payed) {
        Page<WelcomeProgress> page = Page.of(pageNumber, pageSize);
        QueryWrapper<WelcomeProgress> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq(registered!=null,"registered",registered)
                .eq(roomed!=null,"roomed",roomed)
                .eq(geted!=null,"geted",geted)
                .eq(payed!=null,"payed",payed);
        page(page,queryWrapper);
        return page;
    }
}
